package ro.gateway.aida.obj;

import java.util.*;
import java.text.NumberFormat;

import ro.gateway.aida.admin.PropertyListItem;
import ro.gateway.aida.fnd.FundingItem;


/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: :D application</p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: Romania Development Gateway </p>
 *
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: Activity.java,v 1.1 2004/10/24 23:37:10 mihaipostelnicu Exp $
 */
public class Activity {
	private long id = -1;
	private long parentId = -1;
	private long date_pa = -1;
	private long date_aa = -1;
	private long date_ps = -1;
	private long date_as = -1;
	private long date_pe = -1;
	private long date_ae = -1;
	private boolean approved;
	private ActivityStatus status;
	private boolean status_automation_on = false;
	private long date_ext = -1;
	// o activitatea are si un obiect de tip object pt. date
	// legate de harvestire, etc.
	private AIDAActivityObject objectData;
	// titlurile activitatii
	private GenericActivityProperty gen_titles;
	private GenericActivityProperty gen_ext_reasons;
	private GenericActivityProperty gen_descriptions;
	private GenericActivityProperty gen_objectives;
	private GenericActivityProperty gen_results;
	private GenericActivityProperty gen_status_reasons;
	private GenericActivityProperty gen_keywords;
	private GenericActivityProperty gen_bencomment;
	private GenericActivityProperty gen_notefield1;
	private GenericActivityProperty gen_notefield2;
	private GenericActivityProperty gen_notefield3;
	private GenericActivityProperty gen_notefield4;
	private ArrayList gen_components;
//     private Hashtable s_titles;
//     private Hashtable s_ext_reasons;
//     private Hashtable s_descriptions;
//     private Hashtable s_objectives;
//     private Hashtable s_results;
//     private Hashtable s_status_reasons;
//     private Hashtable s_keywords;
//     private ArrayList components;
	private ArrayList resources;
	private ArrayList documents;
//      private ArrayList funding_items;
	private Hashtable hash_donor_prj_ids;
	private boolean transfrontalier = false;
	private boolean international = false;
	private AIDALocation[] locations;
	private AIDAObjSector[] sectors;
	private ArrayList org_involved;
	// de ce folosesc obiectul PersonInv cand pot folosi
	// Person? pt. forma de editare... sa grupez persoanele
	// dupa rolul organizatiei din care face parte, rol
	// in activitatea care se editeaza
	private ArrayList persons_involved;
	private ArrayList act_relations;
	private ArrayList beneficiaries;
	// relative url to logo file
	private String logo_url;
	// categories
	private ArrayList categories;
	// funding items (ver 2)
	// key = Long(org_id)
	private Hashtable byOrgFndItems;
	ContactInfo contact;
	String infoSource;
	private String view_lang;

	public String getView_lang() {
		return view_lang;
	}

	public void setView_lang(String view_lang) {
		this.view_lang = view_lang;
		if (sectors != null) {
			for (int i = 0; i < sectors.length; i++) {
				sectors[i].setView_lang(view_lang);
			}
			Arrays.sort(sectors, new AIDAObjSector$Comparator());
		}
	}

	public String getInfoSource() {
		return infoSource;
	}

	public void setInfoSource(String infoSource) {
		this.infoSource = infoSource;
	}

	/**
	 *
	 */
	public Activity() {
		gen_titles = new GenericActivityProperty(GenericActivityProperty.TYPE_TITLE);
		gen_ext_reasons = new GenericActivityProperty(GenericActivityProperty.TYPE_EXT_REASON);
		gen_descriptions = new GenericActivityProperty(GenericActivityProperty.TYPE_DESCRIPTION);
		gen_objectives = new GenericActivityProperty(GenericActivityProperty.TYPE_OBJECTIVE);
		gen_results = new GenericActivityProperty(GenericActivityProperty.TYPE_RESULT);
		gen_status_reasons = new GenericActivityProperty(GenericActivityProperty.TYPE_STATUS);
		gen_keywords = new GenericActivityProperty(GenericActivityProperty.TYPE_KEYWORDS);
		gen_bencomment = new GenericActivityProperty(GenericActivityProperty.TYPE_BENEFICIARIES_COMMENT);
		gen_notefield1 = new GenericActivityProperty(GenericActivityProperty.TYPE_NOTE_FIELD_1);
		gen_notefield2 = new GenericActivityProperty(GenericActivityProperty.TYPE_NOTE_FIELD_2);
		gen_notefield3 = new GenericActivityProperty(GenericActivityProperty.TYPE_NOTE_FIELD_3);
		gen_notefield4 = new GenericActivityProperty(GenericActivityProperty.TYPE_NOTE_FIELD_4);
//          this.s_titles = new Hashtable();
//          this.s_ext_reasons = new Hashtable();
//          this.s_descriptions = new Hashtable();
//          this.s_objectives = new Hashtable();
//          this.s_results = new Hashtable();
//          this.s_status_reasons = new Hashtable();
//          this.s_keywords = new Hashtable();
		this.locations = new AIDALocation[0];
		this.sectors = new AIDAObjSector[0];
		this.org_involved = new ArrayList();
		this.persons_involved = new ArrayList();
		this.hash_donor_prj_ids = new Hashtable();
		this.gen_components = new ArrayList();
		this.resources = new ArrayList();
		this.documents = new ArrayList();
//            this.funding_items = new ArrayList();
		this.act_relations = new ArrayList();
		this.categories = new ArrayList();
		this.byOrgFndItems = new Hashtable();
		this.contact = new ContactInfo();
		this.beneficiaries = new ArrayList();
	}


	public boolean isStatus_automation_on() {
		return status_automation_on;
	}

	public void setStatus_automation_on(boolean status_automation_on) {
		this.status_automation_on = status_automation_on;
	}

	public ArrayList getBeneficiaries() {
		return beneficiaries;
	}

	public void setBeneficiaries(ArrayList beneficiaries) {
		this.beneficiaries = beneficiaries;
	}

	public boolean containsBeneficiary(long id) {
		for (int i = 0; i < beneficiaries.size(); i++) {
			PropertyListItem item = (PropertyListItem) beneficiaries.get(i);
			if (item.getId() == id) return true;
		}
		return false;
	}

	public ContactInfo getContact() {
		return contact;
	}

	public void setContact(ContactInfo contact) {
		this.contact = contact;
		if (this.contact == null) {
			this.contact = new ContactInfo();
			this.contact.activity_id = this.id;
		}
	}

	public ArrayList getFndItemsForOrg(long org_id) {
		ArrayList result = (ArrayList) byOrgFndItems.
			  get(new Long(org_id));

		return result;
	}

	public void addFndItem(FundingItem item) {
		Long org_id = new Long(item.getOrg_id());
		ArrayList items = (ArrayList) byOrgFndItems.get(org_id);
		if (items == null) {
			items = new ArrayList();
			byOrgFndItems.put(org_id, items);
		}
		items.add(item);
	}

	public FundingItem getFndItem(long org_id, int item_idx) {
		Long lorg_id = new Long(org_id);
		ArrayList items = (ArrayList) byOrgFndItems.get(lorg_id);
		if (items == null
			  || item_idx < 0
			  || item_idx >= items.size())
			return null;
		return (FundingItem) items.get(item_idx);
	}

	public void updateFndItem(FundingItem item, int item_idx) {
		ArrayList items = (ArrayList) byOrgFndItems.get(new Long(item.getOrg_id()));
		if (items == null) return;
		if (item_idx >= 0 && item_idx < items.size()) {
			FundingItem to_update = (FundingItem) items.get(item_idx);
			to_update.populate(item);
		}
	}

	public Category[] getCategoriesArray() {
		if (categories.size() > 0) {
			Category[] result = new Category[categories.size()];
			categories.toArray(result);
			return result;
		}
		return null;
	}

	public ArrayList getCategories() {
		return categories;
	}

	public void setCategories(ArrayList categories) {
		this.categories = categories;
	}

	/**
	 * Verifica daca relatiile cu celelalte proiecte sint corecte
	 * si repara ev. nesimetrii
	 */
	public void make_simetric_relations() {
		synchronized (act_relations) {
			// parent_of
			ArrayList me_pof = new ArrayList();
			// child_of
			ArrayList cof_me = new ArrayList();
			// after
			ArrayList me_aft = new ArrayList();
			// before
			ArrayList bef_me = new ArrayList();

			for (int i = 0; i < act_relations.size(); i++) {
				ActivityRelation rel = (ActivityRelation) act_relations.get(i);
				if ("parent_of".equals(rel.getRelation())) {
					if (me_pof.contains(rel)) continue;
					me_pof.add(rel);
					ActivityRelation sim_rel = new ActivityRelation();
					sim_rel.setRelation("child_of");
					sim_rel.setActivity_id(rel.getRelto_activity_id());
					sim_rel.setRelto_activity_id(rel.getActivity_id());
					cof_me.add(sim_rel);
				} else if ("after".equals(rel.getRelation())) {
					if (me_aft.contains(rel)) continue;
					me_aft.add(rel);
					ActivityRelation sim_rel = new ActivityRelation();
					sim_rel.setRelation("before");
					sim_rel.setActivity_id(rel.getRelto_activity_id());
					sim_rel.setRelto_activity_id(rel.getActivity_id());
					bef_me.add(sim_rel);
				} else if ("child_of".equals(rel.getRelation())) {
					if (cof_me.contains(rel)) continue;
					cof_me.add(rel);
					ActivityRelation sim_rel = new ActivityRelation();
					sim_rel.setRelation("parent_of");
					sim_rel.setActivity_id(rel.getRelto_activity_id());
					sim_rel.setRelto_activity_id(rel.getActivity_id());
					me_pof.add(sim_rel);
				} else if ("before".equals(rel.getRelation())) {
					if (bef_me.contains(rel)) continue;
					bef_me.add(rel);
					ActivityRelation sim_rel = new ActivityRelation();
					sim_rel.setRelation("after");
					sim_rel.setActivity_id(rel.getRelto_activity_id());
					sim_rel.setRelto_activity_id(rel.getActivity_id());
					me_aft.add(sim_rel);
				}
			}

			this.act_relations.clear();
			this.act_relations.addAll(cof_me);
			this.act_relations.addAll(me_pof);
			this.act_relations.addAll(bef_me);
			this.act_relations.addAll(me_aft);
			for (int i = 0; i < act_relations.size(); i++) {
				ActivityRelation activityRelation = (ActivityRelation) act_relations.get(i);
//                        System.out.println( activityRelation );
			}
		}
	}

	public String getLogo_url() {
		return logo_url;
	}

	public void setLogo_url(String logo_url) {
		this.logo_url = logo_url;
	}

	public void setAct_relations(ArrayList act_relations) {
		synchronized (act_relations) {
			this.act_relations = act_relations;
		}
	}

	public ArrayList getAct_relations() {
		synchronized (act_relations) {
			return act_relations;
		}
	}

	public ActivityRelation[] getAct_relationsArray() {
		synchronized (act_relations) {
			if (act_relations.size() == 0) {
				return null;
			}

			ActivityRelation[] result = new ActivityRelation[act_relations.size()];
			act_relations.toArray(result);

			return result;
		}
	}

	public void setGen_keywords(GenericActivityProperty gen_keywords) {
		this.gen_keywords = gen_keywords;
		if (this.gen_keywords == null) this.gen_keywords = new GenericActivityProperty(GenericActivityProperty.TYPE_KEYWORDS);
	}

	public void setGen_status_reasons(GenericActivityProperty gen_status_reasons) {
		this.gen_status_reasons = gen_status_reasons;
		if (this.gen_status_reasons == null) this.gen_status_reasons = new GenericActivityProperty(GenericActivityProperty.TYPE_STATUS);
	}

	public void setGen_results(GenericActivityProperty gen_results) {
		this.gen_results = gen_results;
		if (this.gen_results == null) this.gen_results = new GenericActivityProperty(GenericActivityProperty.TYPE_RESULT);
	}

	public void setGen_objectives(GenericActivityProperty gen_objectives) {
		this.gen_objectives = gen_objectives;
		if (this.gen_objectives == null) this.gen_objectives = new GenericActivityProperty(GenericActivityProperty.TYPE_OBJECTIVE);
	}

	public void setGen_descriptions(GenericActivityProperty gen_descriptions) {
		this.gen_descriptions = gen_descriptions;
		if (this.gen_descriptions == null) this.gen_descriptions = new GenericActivityProperty(GenericActivityProperty.TYPE_DESCRIPTION);
	}

	public void setGen_notefield1(GenericActivityProperty notefield) {
		this.gen_notefield1 = notefield;
		if (this.gen_notefield1 == null) this.gen_notefield1 = new GenericActivityProperty(GenericActivityProperty.TYPE_NOTE_FIELD_1);
	}

	public void setGen_notefield2(GenericActivityProperty notefield) {
		this.gen_notefield2 = notefield;
		if (this.gen_notefield2 == null) this.gen_notefield2 = new GenericActivityProperty(GenericActivityProperty.TYPE_NOTE_FIELD_2);
	}

	public void setGen_notefield3(GenericActivityProperty notefield) {
		this.gen_notefield3 = notefield;
		if (this.gen_notefield3 == null) this.gen_notefield3 = new GenericActivityProperty(GenericActivityProperty.TYPE_NOTE_FIELD_3);
	}

	public void setGen_notefield4(GenericActivityProperty notefield) {
		this.gen_notefield4 = notefield;
		if (this.gen_notefield4 == null) this.gen_notefield4 = new GenericActivityProperty(GenericActivityProperty.TYPE_NOTE_FIELD_4);
	}

	public void setGen_ext_reasons(GenericActivityProperty gen_ext_reasons) {
		this.gen_ext_reasons = gen_ext_reasons;
		if (this.gen_ext_reasons == null) this.gen_ext_reasons = new GenericActivityProperty(GenericActivityProperty.TYPE_EXT_REASON);
	}

	public void setGen_titles(GenericActivityProperty gen_titles) {
		this.gen_titles = gen_titles;
		if (this.gen_titles == null) this.gen_titles = new GenericActivityProperty(GenericActivityProperty.TYPE_TITLE);
	}

	public void setGen_bencomment(GenericActivityProperty gen_bencomment) {
		this.gen_bencomment = gen_bencomment;
		if (this.gen_bencomment == null) this.gen_bencomment = new GenericActivityProperty(GenericActivityProperty.TYPE_BENEFICIARIES_COMMENT);
	}

	public GenericActivityProperty getGen_keywords() {
		return gen_keywords;
	}

	public GenericActivityProperty getGen_status_reasons() {
		return gen_status_reasons;
	}

	public GenericActivityProperty getGen_results() {
		return gen_results;
	}

	public GenericActivityProperty getGen_objectives() {
		return gen_objectives;
	}

	public GenericActivityProperty getGen_bencomment() {
		return gen_bencomment;
	}

	public GenericActivityProperty getGen_descriptions() {
		return gen_descriptions;
	}

	public GenericActivityProperty getGen_notefield1() {
		return gen_notefield1;
	}

	public GenericActivityProperty getGen_notefield2() {
		return gen_notefield2;
	}

	public GenericActivityProperty getGen_notefield3() {
		return gen_notefield3;
	}

	public GenericActivityProperty getGen_notefield4() {
		return gen_notefield4;
	}

	public GenericActivityProperty getGen_ext_reasons() {
		return gen_ext_reasons;
	}

	public GenericActivityProperty getGen_titles() {
		return gen_titles;
	}

	public FundingItem[] getFunding_itemsArray() {
		ArrayList items = new ArrayList();

		Enumeration en = byOrgFndItems.keys();
		while (en.hasMoreElements()) {
			Long org_id = (Long) en.nextElement();
			Collection col = (ArrayList) byOrgFndItems.get(org_id);
			if (col != null) {
				items.addAll(col);
			}
		}
		if (items.size() < 1) {
			return null;
		}
		FundingItem[] result = new FundingItem[items.size()];
		items.toArray(result);

		return result;
	}

	public void addComponent(GenericActivityProperty component) {
		for (int i = 0; i < gen_components.size(); i++) {
			GenericActivityProperty aidaComponent = (GenericActivityProperty) gen_components.get(i);
			if (aidaComponent.equals(component)) {
				return;
			}
		}
		this.gen_components.add(component);
	}

	public void addComponents(GenericActivityProperty components[]) {
		if (components != null)
			for (int i = 0; i < components.length; i++) {
				addComponent(components[i]);
			}
	}

	public GenericActivityProperty[] getComponents() {
		if (this.gen_components.size() > 0) {
			GenericActivityProperty result[] =
				  new GenericActivityProperty[this.gen_components.size()];
			this.gen_components.toArray(result);
			return result;
		} else {
			return null;
		}
	}

	public void removeComponent(int index) {
		if ((index >= 0) && (index < gen_components.size())) {
			this.gen_components.remove(index);
		}
	}

	public void addResources(AidaResource[] resources) {
		if (resources != null)
			for (int i = 0; i < resources.length; i++) {
				addResource(resources[i]);
			}
	}

	public void addResource(AidaResource resource) {
		for (int i = 0; i < resources.size(); i++) {
			AidaResource aidaResource = (AidaResource) resources.get(i);
			if (aidaResource.equals(resource)) {
				return;
			}
		}
		this.resources.add(resource);
	}

	public ArrayList getDocsList() {
		return documents;
	}

	public ArrayList getResourcesList() {
		return this.resources;
	}

	public AidaResource[] getResources() {
		if (this.resources.size() > 0) {
			AidaResource result[] = new AidaResource[this.resources.size()];
			this.resources.toArray(result);
			return result;
		} else {
			return null;
		}
	}

	public void removeResource(int index) {
		if ((index >= 0) && (index < resources.size())) {
			this.resources.remove(index);
		}
	}

	public void addDocument(AIDADocument[] documents) {
		if (documents != null) {
			for (int i = 0; i < documents.length; i++) {
				addDocument(documents[i]);
			}
		}
	}

	public void addDocument(AIDADocument document) {
		for (int i = 0; i < documents.size(); i++) {
			AIDADocument aidaDocument = (AIDADocument) documents.get(i);
			if (aidaDocument.equals(document)) {
				return;
			}
		}
		this.documents.add(document);
	}

	public AIDADocument[] getDocuments() {
		if (this.documents.size() > 0) {
			AIDADocument result[] = new AIDADocument[this.documents.size()];
			this.documents.toArray(result);
			return result;
		} else {
			return null;
		}
	}

	public void removeDocument(int index) {
		if ((index >= 0) && (index < documents.size())) {
			this.documents.remove(index);
		}
	}

	/**
	 * @param local_role_id
	 * @return
	 */
	public PersonInv[] getPersonsByLRId(Integer local_role_id) {
		PersonInv[] result = null;

		ArrayList items = new ArrayList();
		for (int i = 0; i < persons_involved.size(); i++) {
			PersonInv o = (PersonInv) persons_involved.get(i);
			if (o.role.getId() == local_role_id) {
				items.add(o);
			}
		}

		if (items.size() > 0) {
			result = new PersonInv[items.size()];
			items.toArray(result);
		}

		return result;
	}

	public PersonInv[] getPersons() {
		if (persons_involved.size() < 1) {
			return null;
		}

		PersonInv[] result = new PersonInv[persons_involved.size()];
		persons_involved.toArray(result);
		return result;
	}

	/**
	 * @param local_role_id
	 * @return
	 */
	public PersonInv[] removePersonsByLRoleId(Integer local_role_id) {
		PersonInv[] result = null;

		ArrayList items = new ArrayList();
		for (int i = 0; i < persons_involved.size(); i++) {
			PersonInv o = (PersonInv) persons_involved.get(i);
			if (o.role.getId() == local_role_id) {
				items.add(o);
				persons_involved.remove(i);
				i--;
				continue;
			}
		}

		if (items.size() > 0) {
			result = new PersonInv[items.size()];
			items.toArray(result);
		}

		return result;
	}

	/**
	 * @param persons
	 */
	public void addPersons(PersonInv[] persons) {
		if (persons == null) return;
		for (int i = 0; i < persons.length; i++) {
			this.persons_involved.add(persons[i]);
		}
	}

	/**
	 * returns organizations involved by local role id
	 *
	 * @param local_role_id
	 * @return
	 */
	public OrganizationInv[] getOrgsByLRId(Integer local_role_id) {
		OrganizationInv[] result = null;

		ArrayList items = new ArrayList();
		for (int i = 0; i < org_involved.size(); i++) {
			OrganizationInv o = (OrganizationInv) org_involved.get(i);
			if (o.role.getId() == local_role_id) {
				items.add(o);
			}
		}

		if (items.size() > 0) {
			result = new OrganizationInv[items.size()];
			items.toArray(result);
		}

		return result;
	}

	public OrganizationInv[] getFundingOrgs() {
		return getOrgsByLRId(OrganizationRole.FINANCING_ORG_ROLE);
	}

	public OrganizationInv getOrgByLRIId(Integer local_role_id, long id) {
		for (int i = 0; i < org_involved.size(); i++) {
			OrganizationInv o = (OrganizationInv) org_involved.get(i);
			if (o.role.getId() == local_role_id && o.getOrg_id() == id) {
				return o;
			}
		}

		return null;
	}

	public OrganizationInv[] getOrganizations() {
		if (org_involved.size() < 1) {
			return null;
		}

		OrganizationInv[] result = new OrganizationInv[org_involved.size()];
		org_involved.toArray(result);

		return result;
	}

	/**
	 * sterge din lista organizatiile cu rolul specificat
	 *
	 * @return
	 */
	public OrganizationInv[] removeOrgsByLRoleId(Integer local_role_id) {
		OrganizationInv[] result = null;

		ArrayList items = new ArrayList();
		for (int i = 0; i < org_involved.size(); i++) {
			OrganizationInv o = (OrganizationInv) org_involved.get(i);
			if (o.role.getId() == local_role_id) {
				items.add(o);
				org_involved.remove(i);
				i--;
				continue;
			}
		}

		if (items.size() > 0) {
			result = new OrganizationInv[items.size()];
			items.toArray(result);
		}

		return result;
	}

	public void removeOrgByRoleId(Integer local_role_id, long org_id) {
		org_involved.remove(getOrgByLRIId(local_role_id, org_id));
	}

	public boolean containsOrgForRole(Integer role, long org_id) {
		for (int i = 0; i < org_involved.size(); i++) {
			OrganizationInv org = (OrganizationInv) org_involved.get(i);
//                  System.out.println( org_id + "-" + org.getOrg_id() + "-" + org.getOrg().getOrgID() );
			if (org.getOrg_id() == org_id
				  && org.role.getId() == role)
				return true;
		}

		return false;
	}

	public void addOrg(OrganizationInv org, Integer role) {
		if (org == null) return;
		if (role != null && containsOrgForRole(role, org.getOrg_id())) return;
		this.org_involved.add(org);
	}

	public void addOrgs(OrganizationInv[] orgs, Integer role) {
		if (orgs == null) return;
		for (int i = 0; i < orgs.length; i++) {
			addOrg(orgs[i], role);
		}
	}

	public void log_orgs() {
		for (int i = 0; i < org_involved.size(); i++) {
			OrganizationInv organizationInv = (OrganizationInv) org_involved.get(i);
			System.err.print(organizationInv.getOrg().getName() + ":role:");
			System.err.println(organizationInv.role.getId());
		}
	}

	public String getTitle(String lang) {
		return gen_titles.getName(lang);
	}

	public void setTitle(String lang, String title) {
		gen_titles.setName(lang, title);
	}

	public String getBencomment(String lang) {
		return gen_bencomment.getName(lang);
	}

	public void setBencomment(String lang, String bencomment) {
		gen_bencomment.setName(lang, bencomment);
	}

	public void setKeywords(String lang, String keywords) {
		gen_keywords.setName(lang, keywords);
	}

	public String getStatusReason(String lang) {
		return gen_status_reasons.getName(lang);
	}

	public String getKeywords(String lang) {
		return gen_keywords.getName(lang);
	}

	public void setStatusReason(String lang, String status_reason) {
		gen_status_reasons.setName(lang, status_reason);
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getObjective(String lang) {
		return gen_objectives.getName(lang);
	}

	/**
	 * @param lang
	 * @param objective
	 */
	public void setObjective(String lang, String objective) {
		gen_objectives.setName(lang, objective);
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getDescription(String lang) {
		return gen_descriptions.getName(lang);
	}

	/**
	 * @param lang
	 * @param description
	 */
	public void setDescription(String lang, String description) {
		gen_descriptions.setName(lang, description);
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getNoteField1(String lang) {
		return gen_notefield1.getName(lang);
	}

	/**
	 * @param lang
	 * @param value
	 */
	public void setNoteField1(String lang, String value) {
		gen_notefield1.setName(lang, value);
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getNoteField2(String lang) {
		return gen_notefield2.getName(lang);
	}

	/**
	 * @param lang
	 * @param value
	 */
	public void setNoteField2(String lang, String value) {
		gen_notefield2.setName(lang, value);
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getNoteField3(String lang) {
		return gen_notefield3.getName(lang);
	}

	/**
	 * @param lang
	 * @param value
	 */
	public void setNoteField3(String lang, String value) {
		gen_notefield3.setName(lang, value);
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getNoteField4(String lang) {
		return gen_notefield4.getName(lang);
	}

	/**
	 * @param lang
	 * @param value
	 */
	public void setNoteField4(String lang, String value) {
		gen_notefield4.setName(lang, value);
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getResult(String lang) {
		return gen_results.getName(lang);
	}

	/**
	 * @param lang
	 * @param result
	 */
	public void setResult(String lang, String result) {
		gen_results.setName(lang, result);
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getExtensionReason(String lang) {
		return gen_ext_reasons.getName(lang);
	}

	/**
	 * @param lang
	 * @param text
	 */
	public void setExtensionReason(String lang, String text) {
		this.gen_ext_reasons.setName(lang, text);
	}

	/**
	 * @return
	 */
	public AIDAActivityObject getObject() {
		return this.objectData;
	}

	/**
	 * @param objectData
	 */
	public void setObject(AIDAActivityObject objectData) {
		this.objectData = objectData;
	}

	/**
	 * @return
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param id
	 */
	public void setId(long id) {
		this.id = id;
		this.contact.setActivity_id(id);
	}

	/**
	 * @param parentId
	 */
	public void setParentId(long parentId) {
		this.parentId = parentId;
	}

	/**
	 * @return
	 */
	public long getParentId() {
		return parentId;
	}

	/**
	 * @param date_pa
	 */
	public void setDate_pa(long date_pa) {
		this.date_pa = date_pa;
	}

	/**
	 * @return
	 */
	public long getDate_pa() {
		return date_pa;
	}

	/**
	 * @param date_aa
	 */
	public void setDate_aa(long date_aa) {
		this.date_aa = date_aa;
	}

	/**
	 * @return
	 */
	public long getDate_aa() {
		return date_aa;
	}

	/**
	 * @param date_ps
	 */
	public void setDate_ps(long date_ps) {
		this.date_ps = date_ps;
	}

	/**
	 * @return
	 */
	public long getDate_ps() {
		return date_ps;
	}

	/**
	 * @param date_as
	 */
	public void setDate_as(long date_as) {
		this.date_as = date_as;
	}

	/**
	 * @return
	 */
	public long getDate_as() {
		return date_as;
	}

	/**
	 * @param date_pe
	 */
	public void setDate_pe(long date_pe) {
		this.date_pe = date_pe;
	}

	/**
	 * @return
	 */
	public long getDate_pe() {
		return date_pe;
	}

	/**
	 * @param date_ae
	 */
	public void setDate_ae(long date_ae) {
		this.date_ae = date_ae;
	}

	/**
	 * @return
	 */
	public long getDate_ae() {
		return date_ae;
	}

	/**
	 * @param status
	 */
	public void setStatus(ActivityStatus status) {
		this.status = status;
	}

	/**
	 * @return
	 */
	public ActivityStatus getStatus() {
		return status;
	}

	/**
	 * @return
	 */
	public boolean hasId() {
		return this.id != -1;
	}

	/**
	 * @return
	 */
	public boolean hasParent() {
		return this.parentId != -1;
	}

	/**
	 * @param date_ext
	 */
	public void setDate_ext(long date_ext) {
		this.date_ext = date_ext;
	}

	/**
	 * @return
	 */
	public long getDate_ext() {
		return date_ext;
	}

	public void setTransfrontalier(boolean transfrontalier) {
		this.transfrontalier = transfrontalier;
	}

	public boolean isTransfrontalier() {
		return transfrontalier;
	}

	public void setInternational(boolean international) {
		this.international = international;
	}

	public boolean isInternational() {
		return international;
	}

	public synchronized void addLocation(AIDALocation location) {
		if (containsLocation(location)) {
			return;
		}

		AIDALocation[] new_locations = new AIDALocation[locations.length + 1];
		System.arraycopy(locations, 0, new_locations, 0, locations.length);
		new_locations[locations.length] = location;
		locations = new_locations;

		Arrays.sort(locations, new Comparator() {
			public int compare(Object o1, Object o2) {
				AIDALocation l1 = (AIDALocation) o1;
				AIDALocation l2 = (AIDALocation) o2;
				return l1.getCregion().getName().compareTo(l2.getCregion().getName());
			}
		});
	}

	public synchronized Country[] getLocationCountries() {
		if (locations.length < 1) return null;

		ArrayList items = new ArrayList();
		for (int i = 0; i < locations.length; i++) {
			if (!items.contains(locations[i].getCountry()))
				items.add(locations[i].getCountry());
		}

		Country[] result = null;
		if (items.size() > 0) {
			result = new Country[items.size()];
			items.toArray(result);
		}
		return result;
	}

	public synchronized void addSector(AIDAObjSector sector) {
		if (containsSector(sector)) {
			return;
		}

		AIDAObjSector[] new_sectors = new AIDAObjSector[sectors.length + 1];
		System.arraycopy(sectors, 0, new_sectors, 0, sectors.length);
		new_sectors[sectors.length] = sector;
		Arrays.sort(new_sectors, new AIDAObjSector$Comparator());
		sectors = new_sectors;
	}

	public boolean containsLocation(AIDALocation location) {
		for (int i = 0; i < locations.length; i++) {
			if (locations[i].equals(location))
				return true;
		}
		return false;
	}

	public boolean containsSector(AIDAObjSector sector) {
		for (int i = 0; i < sectors.length; i++) {
			if (sectors[i].equals(sector))
				return true;
		}
		return false;
	}

	public synchronized void removeLocation(AIDALocation location) {
		int index = -1;
		for (int i = 0; i < locations.length; i++) {
			if (locations[i].equals(location)) {
				index = i;
				break;
			}
		}
		if (index != -1) {
			removeLocation(index);
		}
	}

	public synchronized void removeLocation(int index) {
		if ((index >= 0) && (index < locations.length)) {
			AIDALocation[] new_locations = new AIDALocation[this.locations.length - 1];
			if (index > 0) {
				System.arraycopy(this.locations, 0, new_locations, 0, index);
			}
			if (index < locations.length - 1) {
				System.arraycopy(this.locations, index + 1, new_locations, index,
					  this.locations.length - index - 1);
			}
			this.locations = new_locations;
		}
	}

	public synchronized void removeSector(int index) {
		if ((index >= 0) && (index < sectors.length)) {
			AIDAObjSector[] new_sectors = new AIDAObjSector[this.sectors.length - 1];
			if (index > 0) {
				System.arraycopy(this.sectors, 0, new_sectors, 0, index);
			}
			if (index < sectors.length - 1) {
				System.arraycopy(this.sectors, index + 1, new_sectors, index,
					  this.sectors.length - index - 1);
			}
			this.sectors = new_sectors;
		}
	}

	public AIDALocation[] getLocations() {
		return this.locations;
	}

	public void removeAllLocations() {
		this.locations = new AIDALocation[0];
	}

	public AIDAObjSector[] getSectors() {
		return this.sectors;
	}

	public void clearDonor_prj_ids() {
		this.hash_donor_prj_ids.clear();
	}

	public String getDonorIdForOrg(long donor_org_id) {
		String result = (String) hash_donor_prj_ids.get(new Long(donor_org_id));
		return result;
	}

	public void setDonorIdForOrg(long donor_org_id, String prj_id) {
		this.hash_donor_prj_ids.put(new Long(donor_org_id), prj_id);
	}

	public Hashtable getHash_donor_prj_ids() {
		return hash_donor_prj_ids;
	}

	public void removeDonorPrjId(long id) {
		hash_donor_prj_ids.remove(new Long(id));
	}

	public void clearStatusReasons() {
		this.gen_status_reasons.clearNames();
	}

	public void removeLocationsButForCountry(String country_iso3) {
		if (country_iso3 == null)
			return;

		ArrayList items = new ArrayList();
		for (int i = 0; i < locations.length; i++) {
			if (country_iso3.equals(locations[i].getCountry().getIso3()))
				items.add(locations[i]);
		}

		AIDALocation[] new_locations = new AIDALocation[items.size()];
		items.toArray(new_locations);

		this.locations = new_locations;
	}

	/**
	 * editing variables
	 * membri folositi doar in procesul de editare...
	 * interesant pt. dezvoltatorii de interfata.
	 */
	public String __wed_sel_country = null;

	/**
	 * @return
	 */
	public boolean isApproved() {
		return approved;
	}

	/**
	 * @param b
	 */
	public void setApproved(boolean b) {
		approved = b;
	}

	public void addCategory(Category category) {
		this.categories.add(category);
	}

	public void removeFundingItemsForOrg(long org_id) {
//            System.out.println( "removing fitems for org:" + org_id );
		byOrgFndItems.remove(new Long(org_id));
	}


	/**
	 * @return
	 */
	public ArrayList getPersons_involved() {
		return persons_involved;
	}

	/**
	 * @param list
	 */
	public void setPersons_involved(ArrayList list) {
		persons_involved = list;
	}

	public Hashtable getProjectBudget() {
		Hashtable result = new Hashtable();
		FundingItem[] fitems = this.getFunding_itemsArray();
		if (fitems != null)
		for (int i = 0; i < fitems.length; i++) {
			FundingItem fitem = fitems[i];
			String currency = fitem.getCurrency();
			if (currency == null) continue;
			double amount = fitem.getAmount();
			Double current_amount = (Double) result.get(currency);
			current_amount = new Double((current_amount != null ? current_amount.doubleValue() : 0) + amount);
			result.put(currency, current_amount);
		}
		return result;
	}

	public String getProjectBudgetAsString(Locale locale, String delimiter) {
		StringBuffer sb = new StringBuffer();
		Hashtable pb = getProjectBudget();
		Enumeration en = pb.keys();
		NumberFormat nf = NumberFormat.getInstance(locale);
		while (en.hasMoreElements()) {
			String currency = (String) en.nextElement();
			double value = ((Double) pb.get(currency)).doubleValue();
			sb.append(nf.format(value)).append(" ").append(currency).append(delimiter);
		}
		return sb.toString();
	}
}